<?php
require_once("thumbncrop.inc.php");
class CImage {
	public $image;
	public $file_name;
	public $gd_image;
	static $init_asido = false;
	public $thumbname;

	function __construct($file_name)
	{
		try
		{
			CImage::$init_asido = true;
			$this->file_name = $file_name;


		}
		catch(Exception $e)
		{
			CLog('ERROR', $e->getMessage());
		}
	}
	function thumb($width, $height,$thumb){
		$tb = new ThumbAndCrop();
		$tb->openImg($this->file_name);
		$newHeight = $tb->getRightHeight(100);
		$tb->creaThumb(100, $newHeight);
		$tb->setThumbAsOriginal();
		$tb->resetOriginal();
		$tb->creaThumb($width, $height);
		$tb->saveThumb($thumb);
		$tb->closeImg();
	}

	public function thumbImage($width,$height){
		$thumbname = substr($this->file_name,0,-4).'x'.$width.'x'.$height.substr($this->file_name,-4);
		if(!file_exists($thumbname)) {
			$this->thumb($width, $height,$thumbname);
		}
		return $thumbname;
	}

}
function CImage($file_name)
{
	return new CImage($file_name);
}
?>